package com.magicstone.common;

import java.net.URL;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;

/*
 * http://blog.csdn.net/jammiwang19870815/article/details/9175607
 */
public class MyResourceLoader extends DefaultResourceLoader {
	private final static Log logger = LogFactory.getLog(MyResourceLoader.class);
	
	@Override
	public Resource getResource(String location) {
		if (location != null && location.startsWith("/WEB-INF/")) {
			try {
				URL url = new URL("file:/" + System.getProperty("user.dir") + "/WebRoot" + location);
				return new UrlResource(url);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		return super.getResource(location);
	}
}
